package com.mastercard

import java.util.Date;

import com.mastercard.auth.User
import com.mastercard.common.utils.DateUtil;
class CreditCard{
	
	static auditable = true
	String nameOnCard
	String cardName
	String number
	Date expiryDate
	String ccv2
	
	String expiryDateStr
	String encryptNumber
	
	List transactions
	//List budgets
	
	//static belongsTo = [user:User, bank:Bank]
	//static hasMany = [budgets: Budget, transactions:Transaction]
    static constraints = {
		expiryDate nullable: true
		nameOnCard nullable: true
		cardName nullable: true
		ccv2 nullable: true
		transactions nullable: true
		//user nullable: true
		//bank nullable: true
		//budgets nullable: true
    }
	static transients = ['expiryDateStr','encryptNumber']
	
	String getExpiryDateStr(){
		DateUtil.formatDate(expiryDate, "mm/yyyy")
	}
	
	String getEncryptNumber(){
		if(number.size() > 12){
			"************" + number.substring(12)
		}
	}
}
